# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pybind11
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.13.6
pkgrel=2
pkgdesc="Seamless operability between C++11 and Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://pybind11.readthedocs.org/'
msys2_repository_url="https://github.com/pybind/pybind11"
msys2_references=(
  'purl: pkg:pypi/pybind11'
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-eigen3"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-python-breathe"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx-copybutton"
             "${MINGW_PACKAGE_PREFIX}-python-sphinxcontrib-moderncmakedomain"
             "${MINGW_PACKAGE_PREFIX}-python-sphinxcontrib-svg2pdfconverter"
             "${MINGW_PACKAGE_PREFIX}-python-pytest")
options=('!strip')
source=("https://github.com/pybind/pybind11/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('e08cb87f4773da97fa7b5f035de8763abc656d87d5773e62f6da0587d1f0ec20')

build () {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation

  cd "${srcdir}"/python-build-${MSYSTEM}/docs
  make man
}

package() {
  cd "${srcdir}"/python-build-${MSYSTEM}

  # python modules
  cd "${srcdir}"/python-build-${MSYSTEM}
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

   _pyver=$(${MINGW_PREFIX}/bin/python -c "import sys;sys.stdout.write('.'.join(map(str, sys.version_info[:2])))")
  install -d -m755 "${pkgdir}"${MINGW_PREFIX}/{include,lib/{cmake,pkgconfig}}
    cp -r "${pkgdir}"${MINGW_PREFIX}/lib/python${_pyver}/site-packages/pybind11/include/pybind11 "${pkgdir}"${MINGW_PREFIX}/include/pybind11
    cp -r "${pkgdir}"${MINGW_PREFIX}/lib/python${_pyver}/site-packages/pybind11/share/* "${pkgdir}"${MINGW_PREFIX}/lib

  # manpage
  cd "${srcdir}"/python-build-${MSYSTEM}/docs/.build/man
  install -D -m644 "${_realname}.1" -t "${pkgdir}"${MINGW_PREFIX}/share/man/man1

  # license
  install -D -m644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
}
